package hot_problems_100;

public class P19_0048 {
    /*
    * 将矩阵顺时针旋转90度，原地旋转
    *
    * 注意：旋转的公式是通用的
    * */
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for(int i=0; i<n/2; i++){
            for(int j=i; j<n-i-1; j++){
                int x = i, y = j;
                int next_x, next_y ;
                int tmp1 = matrix[x][y], tmp2;

                for(int k=0; k<4; k++){
                    next_x = y;
                    next_y = n - 1 -x;

                    tmp2 = matrix[next_x][next_y];
                    matrix[next_x][next_y] = tmp1;
                    tmp1 = tmp2;
                    x = next_x;
                    y = next_y;
                }
            }
        }
    }
}
